<?
session_start();
include ('../variables.php');
include ('../sessions.php');
include('variables.php');

include_once($baseDIR.'/init.php');
//include('session_check.php');
//$webDIR="login";
//$save_type="MySQL";

$dbh = get_master_connect();
if (!$dbh) {
		echo "We are sorry but we cannot process your request at the moment<BR>";
		exit_now();
}

// Decode query string
if($_SERVER['QUERY_STRING']){
  $params = decode_params();
  if($params) {
    while(list($key,$value) = each($params)){
    	$$key  = $value;
    }
  }
  $params = '';
}


if (getenv(REQUEST_METHOD) == "POST" || ($username && $password)) {
	// Patched version for World pay order type form
	$userName =  strtolower(validate( (($_REQUEST['username']) ? $_REQUEST[username] : $username ), 'username'));
	$passWord = validate((($_REQUEST['password']) ? $_REQUEST['password'] : $password), 'password');
	if (!$userName || !$password) header("Location: $baseURL/login.html");
	if (!check_user_pass($userName, $passWord)) {
		
		header("Location: $baseURL/login.html?errorMsg=wrong password");
	}
	else {
//		kill_old_sessions();
		//$sid = session_get_unique_id();
		$errorMsg = "";
		$okMsg = "";
		$statusMsg = "";
		$id = get_reseller_id($userName);
		$resellerCountry = get_reseller_country($id);
		$_SESSION['memberAuthenticated'] = true;
		$_SESSION['userName'] = $userName;
//		$_SESSION['reseller_id'] = $id;
		$_SESSION['id'] = $id;
//		session_register_(array(errorMsg, okMsg, statusMsg, memberAuthenticated, userName, passWord, id, resellerCountry), sid);
//		session_save(sid);
//		$params['sid'] = $sid;
		$params['action'] = 1;
		if (!empty($action)) {
			$params['action'] = $action;
		}
		if (!empty($plan)) {
			$params['plan'] = $plan;
		}
//		echo ';;;';
//		print_r($_SESSION);
		
		$url="$baseURL/?".encode_params($params);
		header("Location: $url");
	}
}

?>
